const express=require("express");
const app=express();
// 使用设置好的端口，如果没有默认，就用5002
const port =process.env.PROT || 5004
const mongoose =require('mongoose');
const db =require('./config/keys').mongoURI;
const users=require('./routers/api/users')
const bodyParser=require('body-parser')
const passport=require('passport')
const profiles=require('./routers/api/profiles')

mongoose.connect(db,{useNewUrlParser: true,useUnifiedTopology:true})
.then(()=>{
    console.log('数据库连接成功')
}).catch((err)=>{
    console.log(err);
})
mongoose.set('useFindAndModify', false);
//body-parser
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())

//passport
app.use(passport.initialize());
//验证的操作：结合passport与passport-jwt 两模块结合使用
require('./config/passport')(passport)
app.get('/',function(req,res){
    res.send('hello world!')
})
//挂载路由地址 
app.use('/api/users',users)
app.use('/api/profile',profiles)

app.listen(port,()=>{
    console.log(port)
})
// 